package cn.wolfcode.wolf2w.business.service.impl;

import cn.wolfcode.wolf2w.business.api.domain.UserinfoEs;
import cn.wolfcode.wolf2w.business.repository.UserinfoEsRepository;
import cn.wolfcode.wolf2w.business.service.IUserinfoEsService;
import cn.wolfcode.wolf2w.member.api.RemoteUserInfoService;
import cn.wolfcode.wolf2w.member.api.domain.UserInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserinfoEsServiceImpl implements IUserinfoEsService {
    @Autowired
    private UserinfoEsRepository repository;
    @Autowired
    private RemoteUserInfoService remoteUserinfoService;

    @Override
    public void initUserinfoEs() {
        List<UserInfo> list = remoteUserinfoService.list("inner").getData();
        for (UserInfo userinfo : list) {
            UserinfoEs es = new UserinfoEs();
            /**
             * 属性拷贝方法，会将同名属性从source拷贝到target
             * 参数1： source
             * 参数2： target
             * */
            BeanUtils.copyProperties(userinfo, es);
            repository.save(es);
        }
    }
}
